package logic

import (
	"context"
	"errors"
	"home-info-site/models/mysql"

	"home-info-site/userrpc/internal/svc"
	"home-info-site/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserDetailLogic {
	return &UserDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *UserDetailLogic) UserDetail(in *userrpc.UserDetailRequest) (*userrpc.UserDetailResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.User
	err := user.FindUserByUserId(mysql.DB, in.UserId)
	if err != nil {
		return nil, errors.New("用户不存在")
	}

	return &userrpc.UserDetailResponse{
		UserId:    int64(user.ID),
		Tel:       user.Tel,
		Password:  user.Password,
		Username:  user.Username,
		HeadImage: user.HeadImage,
	}, nil
}
